package com.example.mall.user.svc.app.service;

import com.example.mall.common.service.AbstractService;
import com.example.mall.user.svc.app.cmd.BindCmd;
import com.example.mall.user.svc.app.cmd.CreateUserCmd;
import com.example.mall.user.svc.domain.factory.UserFactory;
import com.example.mall.user.svc.infr.mapper.UserMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author Mickey
 * @since 2022/4/15
 **/
@Service
@AllArgsConstructor
public class UserAppService extends AbstractService {

    private final UserMapper userMapper;

    public Long create(CreateUserCmd createUser) {
        return creatorFor(userMapper)
                .instance(() -> UserFactory.instance(createUser, userMapper))
                .call()
                .getId();
    }

    public void bind(BindCmd<?> bindMobile) {
        updaterFor(userMapper)
                .id(bindMobile.getUserId())
                .update(user -> user.bind(bindMobile))
                .call();
    }

}
